using Core.SimpleTemp.Application;
using Core.SimpleTemp.Common.Authorization;
using Core.SimpleTemp.Common.PagingQuery;
using Core.SimpleTemp.Mvc.Api.Internal;
using Core.Toolkit.Authorization;
using Core.Toolkit.Core;
using Core.Toolkit.Core.Api;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Linq;
using System.Threading.Tasks;

namespace Core.SimpleTemp.Api.Api
{
    /// <summary>
    /// JG_STOPObserveMain
    ///</summary>
    [ApiExplorerSettings(GroupName = "Mobile")]//swagger分类标签
    [Route("api/mobile/[controller]")]//路由说明
    [EnableCors("any")]//跨域规则
    [ApiController]//APi标识Controller
    [Authorize]//验证是否登录
    public class JG_STOPObserveMainController : CoreApiController
    {
        private readonly JG_STOPObserveMainService _service;
        /// <summary>
        /// JG_STOPObserveMain
        ///</summary>
        public JG_STOPObserveMainController(JG_STOPObserveMainService service)
        {
            _service = service;
        }

        #region 基础增删改查
        /// <summary>
        /// 查询
        ///</summary>
        /// <param name="pagingQueryModel"></param>
        /// <returns></returns>

        [HttpPost("GetList")]
        [PermissionFilter(nameof(JG_STOPObserveMainController) + "_" + nameof(JG_STOPObserveMainController.GetList), AuthorizationConst.LIST)]
        public async Task<IActionResult>
            GetList(PagingModel<JG_STOPObserveMainDto>
                pagingQueryModel)
        {
            IPageModel<JG_STOPObserveMainDto>
                result = await _service.GetList(pagingQueryModel);
            PageModelObj retObj = new PageModelObj();
            retObj.PageData = result.PageData?.Select(a => new
            {
                a.Id,
                //a.evaluationc,//所有皆安全
                //a.department,//部门
                //a.observePeople,//观察人ID
                //a.observePeopleText,//观察人
                //a.observaDate,//观察日期
                ////a.observation,//观察时间
                //a.shifts,//班次
                //a.situation,//区域
                //a.encourage,//安全行为
                //a.correct,//不安全行为
                //a.State,//状态
                //a.CreateFactory,//隶属工厂
                //a.CreateDept,//添加部门
                //a.UpdateDept,//更改部门
                //a.ryfy_remark,//人员反映备注
                //a.grfhzb_remark,//个人防护装备备注
                //a.rydwz_remark,//人员的位子备注
                //a.gjjsb_remark,//工具及设备备注
                //a.cx_remark,//程序备注
                //a.zxbz_remark,//秩序标准秩序标准
                //a.ryfy_IsSafety,//人员反映其他是否安全
                //a.grfhzb_IsSafety,//个人防护装备是否安全
                //a.rydwz_IsSafely,//人员的位置是否安全
                //a.jjsb_IsSafely,//工具及设备是否安全
                //a.cx_IsSafely,//程序是否安全
                //a.zxbz_IsSafely,//秩序标准
                //a.JG_STOPObserveDetail
            }
            ).ToList();
            retObj.RowCount = result.RowCount;
            return this.JsonSuccess(retObj);
        }

        /// <summary>
        /// 添加/修改
        ///</summary>
        /// <param name="dto"></param>
        /// <returns></returns>

        [HttpPost("Save")]
        [PermissionFilter(nameof(JG_STOPObserveMainController) + "_" + nameof(JG_STOPObserveMainController.SaveAsync), AuthorizationConst.SAVE)]
        public async Task<IActionResult>
            SaveAsync(JG_STOPObserveMainDto dto)
        {
            //添加
            if (Equals(dto.Id, Guid.Empty))
            {
                await _service.InsertAsync(dto);
                return this.JsonSuccess(string.Empty);
            }
            else
            {
                await _service.UpdateAsync(dto);
                return this.JsonSuccess(string.Empty);
            }
        }

        /// <summary>
        /// DeleteMuti
        ///</summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        [HttpPost("DeleteMuti")]
        [PermissionFilter(nameof(JG_STOPObserveMainController) + "_" + nameof(JG_STOPObserveMainController.DeleteMutiAsync), AuthorizationConst.DELETE)]
        public async Task<IActionResult>
            DeleteMutiAsync([FromBody]Guid[] ids)
        {

            await _service.DeleteBatchAsync(ids);
            return this.JsonSuccess();
        }


        /// <summary>
        /// 根据ID获取信息
        ///</summary>
        /// <param name="id"></param>
        /// <returns></returns>

        [HttpGet("Get")]
        public async Task<IActionResult> Get(Guid id)
        {
            var model = await _service.GetAsync(id);
            if (model == null) return this.JsonFaild("未找到对应数据:" + id);
            var retObj = new
            {
                model.evaluationc,//所有皆安全
                model.observePeople,//观察人
                model.department,//部门
                model.shifts,//班次
                model.situation,//区域
                model.observaDate,//观察日期

                //model.observation,//观察时间
                model.encourage,//安全行为
                model.correct,//不安全行为
                //model.State,//状态
                //model.CreateFactory,//隶属工厂
                //model.CreateDept,//添加部门
                //model.UpdateDept,//更改部门

                model.ryfy_remark,//人员反映备注
                model.grfhzb_remark,//个人防护装备备注
                model.rydwz_remark,//人员的位子备注
                model.gjjsb_remark,//工具及设备备注
                model.cx_remark,//程序备注
                model.zxbz_remark,//秩序标准秩序标准

                model.ryfy_IsSafety,//人员反映其他是否安全
                model.grfhzb_IsSafety,//个人防护装备是否安全
                model.rydwz_IsSafety,//人员的位置是否安全
                model.gjjsb_IsSafety,//工具及设备是否安全
                model.cx_IsSafety,//程序是否安全
                model.zxbz_IsSafety,//秩序标准
                JG_STOPObserveDetail = model.JG_STOPObserveDetail.Select(a => new { a.BigType, a.SmallType })
            };
            return this.JsonSuccess(retObj);
        }


        /// <summary>
        /// 导出
        ///</summary>
        /// <param name="pagingQueryModel"></param>
        /// <returns></returns>

        //[HttpPost("Export")]
        //[PermissionFilter(nameof(JG_STOPObserveMainController) + "_" + nameof(JG_STOPObserveMainController.Export), AuthorizationConst.EXPORT)]
        //public async Task<IActionResult>
        //    Export(PagingModel<JG_STOPObserveMainDto>
        //        pagingQueryModel)
        //{
        //    var fileName = await _service.Export(pagingQueryModel);
        //    if (string.IsNullOrWhiteSpace(fileName))
        //        return this.JsonFaild(NULL_DATA_FOR_EXCEL_EXPORT);
        //    return this.JsonSuccess(fileName);
        //}
        #endregion


    }
}
